package com.smart.sso.server.service.impl;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.smart.mvc.model.Pagination;
import com.smart.mvc.service.mybatis.impl.ServiceImpl;
import com.smart.sso.server.dao.UserGroupDao;
import com.smart.sso.server.model.UserGroup;
import com.smart.sso.server.service.UserGroupService;

@Service("userGroupService")
public class UserGroupServiceImpl extends ServiceImpl<UserGroupDao, UserGroup, Integer> implements UserGroupService {

	@Override
	public List<UserGroup> findByUserGroupId(Integer uid, Integer gid) {
		// TODO Auto-generated method stub
		return this.dao.findByUserGroupId(uid, gid);
	}

	@Override
	public void allocate(Integer userId, UserGroup userGroup) {
		// TODO Auto-generated method stub
		this.dao.deleteByUserIds(Arrays.asList(userId));
		super.save(userGroup);
	}

	@Override
	public void deleteByGroupIds(List<Integer> idList) {
		// TODO Auto-generated method stub
		this.dao.deleteByGroupIds(idList);
	}

	@Override
	public void deleteByUserIds(List<Integer> idList) {
		// TODO Auto-generated method stub
		this.dao.deleteByUserIds(idList);
	}

	@Override
	@Autowired
	public void setDao(UserGroupDao dao) {
		// TODO Auto-generated method stub
		this.dao = dao;
	}
	
	@Transactional
	public void deleteById(List<Integer> idList) {
		verifyRows(dao.deleteById(idList), idList.size(), "用户数据库删除失败");
	}

}
